package com.freight.message.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.freight.common.core.constant.SmsConstants;
import com.freight.common.redis.service.RedisService;
import com.freight.message.domain.AlismsConfig;
import com.freight.message.mapper.AlismsConfigMapper;
import com.freight.message.service.IAlismsConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 短信配置Service业务层处理
 *
 * @author ryb
 * @date 2020-12-21
 */
@Service
public class AlismsConfigServiceImpl extends ServiceImpl<AlismsConfigMapper, AlismsConfig> implements IAlismsConfigService {

    @Autowired
    RedisService redisService;

    // 获取阿里短信配置
    @Override
    public AlismsConfig getAlismsConfig() {
        if(redisService.getCacheObject(SmsConstants.CACHE_SMS_CONFIG) != null) {
            return redisService.getCacheObject(SmsConstants.CACHE_SMS_CONFIG);
        }
        List<AlismsConfig> configs = this.list();
        if(configs != null && configs.size() > 0) {
           redisService.setCacheObject(SmsConstants.CACHE_SMS_CONFIG, configs.get(0));
           return configs.get(0);
        }
        return null;
    }

}
